package com.richesup.common.oss.service.impl;/**
 * @Auther: yuhong
 * @Date: 2018-6-26 21:23
 * @Description:
 */

import com.richesup.common.oss.common.CodeMessage;
import com.richesup.common.oss.common.OSSException;
import com.richesup.common.oss.common.ResultEntity;
import com.richesup.common.oss.dao.BucketMapper;
import com.richesup.common.oss.service.IBucket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yuhong
 * @date 2018-06-26 21:23
 * @description
 */
@Service
public class Bucket implements IBucket{

    @Autowired
    BucketMapper bucketMapper;

    /**
     *
     * 功能描述:得到Bucket信息
     *
     * @param: [app_id, bucket_id]
     * @return: com.richesup.common.oss.entity.Bucket
     * @auther: yuhong
     * @date: 2018-6-26 21:24
     */
    @Override
    public com.richesup.common.oss.entity.Bucket verifyBucket(String app_id, String bucket_id) {
        if (app_id==null ||app_id.equals("")) throw new OSSException(ResultEntity.error(CodeMessage.PARAMETER_ISNULL));
        if (bucket_id==null ||bucket_id.equals(""))  throw new OSSException(ResultEntity.error(CodeMessage.PARAMETER_ISNULL));
        com.richesup.common.oss.entity.Bucket bucket= bucketMapper.selectByPrimaryKey(bucket_id);

        if (bucket==null || !bucket.getApp_id().equals(app_id)){
            throw new OSSException(ResultEntity.error(CodeMessage.PERMISSION_DENIED));
        }
        return bucket;
    }
}
